from rest_framework import serializers
from question.models import *

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'

class CommentSerializer1(serializers.ModelSerializer):
    class Meta:
        model = Reply
        fields = '__all__'





class CommentSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    parent = CommentSerializer1()
    class Meta:
        model = Reply
        fields = '__all__'
#
#
#
class AnswerSerializer(serializers.ModelSerializer):
    parent = CommentSerializer1()
    user = UserSerializer()
    subs = serializers.SerializerMethodField()
    class Meta:
        model = Reply
        fields = '__all__'

    def get_subs(self,obj):
        ret = SubSerializer(obj.subs.all(), many=True)
        return ret.data

#
#
class SubSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    class Meta:
        model = Reply
        fields = '__all__'


class ReplySerializer(serializers.ModelSerializer):
    parent_id = serializers.IntegerField()
    class Meta:
        model=Reply

        fields = '__all__'


class QuestionSerializer1(serializers.ModelSerializer):
    answer_question = serializers.SerializerMethodField()
    replies = ReplySerializer(many=True)
    comment_question = serializers.SerializerMethodField()
    user_id = serializers.IntegerField()
    class Meta:
        model=Question

        fields = '__all__'

    def get_comment_question(self,obj):
        srt = CommentSerializer(obj.replies.all(),many=True)

        return srt.data


    def get_answer_question(self,obj):
        ert = AnswerSerializer(obj.replies.all(),many=True)
        return ert.data



class QuestionSerializer(serializers.ModelSerializer):
    user_id = serializers.IntegerField()
    class Meta:
        model=Question

        fields = '__all__'


class QuestionSerializer2(serializers.ModelSerializer):
    # user_id = serializers.IntegerField()
    class Meta:
        model=Question

        fields = '__all__'


class QuestionSerializer3(serializers.ModelSerializer):
    user_id = serializers.IntegerField()
    labels = serializers.StringRelatedField
    class Meta:
        model=Question

        fields = '__all__'